class Student {

}
public class Test {

    public static void main14(String[] args) {
        //string
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        //StringBuffer
        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        //StringBuilder
        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }


    public static void main13(String[] args) {
         /*final int[] array = {1,2,3,4};
         array[0] = 10;  //对
         //array = new int[3]; //错  指向不能改变
*/

       /* String s = "hello";
        s += " world";
        System.out.println(s); // 输出：hello world*/


        String s = "hello";

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(s);
        stringBuilder.append("world");

        s = stringBuilder.toString();

        System.out.println(s);


    }

    public static void main12(String[] args) {
        //字符串截取
        String s = "abcdef";
        //这里如果传入的是0下标 那么默认返回原来的对象 但是如果传入的是其他的对象，
        //此时 返回新的对象
        //String ret = s.substring(0);//abcdef
        String ret = s.substring(1,4);//[1,4)  bcd
        System.out.println(ret);

        String s2 = "   abc   def   ";
        System.out.println(s2);
        //去除 左右两边的空格 保留中间的空格 String.trim()
        String ret1 = s2.trim();
        System.out.println(ret1);


    }

    public static void main11(String[] args) {
        //String str = "192.168.0.0.1";
        /*String str = "192\\168\\0\\0\\1";
        //System.out.println(str);
        String[] strings = str.split("\\\\");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
        */

        /*String str = "name=zhagnsan&age=10";
        String[] strings = str.split("&|=");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }*/
        //多次分割
        String str = "name=zhagnsan&age=10";
        String[] strings = str.split("&");
        for (int i = 0; i < strings.length; i++) {
            //System.out.println(strings[i]);
            String[] strings1 = strings[i].split("=");
            for (int j = 0; j < strings1.length; j++) {
                System.out.println(strings1[j]);
            }
        }
    }

    public static void main10(String[] args) {
        String str = "name=zhagnsan&age=10";
        //分割之后的结果 要存储到 数组当中
        String[] strings = str.split("&");
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
        System.out.println("============");
        String str2 = "hello world hello bit";
        String[] strings2 = str2.split(" ",2);
        for (int i = 0; i < strings2.length; i++) {
            System.out.println(strings2[i]);
        }
    }

    public static void main9(String[] args) {
        String str = "ababcabcdabcde";
        //把所有的ab替换为 oooo  这个替换也是一样 不是在原来字符串的基础上进行替换 他是产生了新的对象
        String ret = str.replace("ab","oooo");
        System.out.println(ret);

        System.out.println("========");

        String ret2 = str.replace('b','z');

        System.out.println(ret2);
        System.out.println("========");

        String ret3 = str.replaceFirst("ab","kk");//只替换一次
        System.out.println(ret3);
        System.out.println("========");
        String ret4 = str.replaceAll("ab","kk");//替换所有的
        System.out.println(ret4);

    }

    public static void main8(String[] args) {
        //字符串转化为数组
        String str1 = "hello";
        char[] array = str1.toCharArray();
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        //格式化
        String s = String.format("%d-%d-%d", 1999, 9,14);
        System.out.println(s);
    }

    public static void main7(String[] args) {
        //大小写转换
        String str1 = "hello";
        String ret = str1.toUpperCase();//String接收
        //java中 String是不可变的 hello->HELLO 这个转换不是在原来的字符串上实现的，是生成了一个新的对象
        System.out.println(ret);

        String str2 = "HEllo";

        String ret2 = str2.toLowerCase();
        System.out.println(ret2);


    }
    public static void main6(String[] args) {
        //数值和字符串转换
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student());

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        //System.out.println(s4);
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);

    }

    public static void main5(String[] args) {
        String str1 = "abcdef";
        //获取指定位置的字符
        char ch = str1.charAt(2);
        System.out.println(ch);//c
        //KMP 算法
        int index = str1.indexOf('c',3);//从3开始查找
        System.out.println(index);

        System.out.println("============");
        String str2 = "ababcdabcdef";

        int index2 = str2.lastIndexOf('a',5);//从后往前找 fromdex也为下标数
        System.out.println(index2);

    }


    public static void main4(String[] args) {
        String str1 = "Abcd";
        String str2 = "abcd";

        //忽略大小写进行 比较
        System.out.println(str1.compareToIgnoreCase(str2));


    }

    public static void main3(String[] args) {
        String str1 = "abcd";
        String str2 = "abcdef";

        //str1大于str2 那么 返回正数  如果不大于 返回负数  如果相同 返回0
        System.out.println(str1.compareTo(str2));
        //System.out.println(str2.compareTo(str1));

        /**
         * 比较逻辑：
         * 1. 如果两个字符串的长度是一样的，那么第一个不一样的字符的大小就是整个字符串的大小
         * 2. 如果两个字符串长度不一样，那么先比较两个长度的差值个
         * 3、在这个差值范围内，有不一样的字符就能比较出来大小
         * 4、但是如果都是一样的，那么就看谁长 谁大 ！
         */

    }

    public static void main2(String[] args) {
        String str1 = new String("abcde");
        String str2 = new String("abcde");

        System.out.println(str1 == str2);

        System.out.println(str1.equals(str2));

        System.out.println("========");

        String str3 = "abcde";
        String str4 = "abcde";
        System.out.println(str3 == str4);//字符串常量池 有哈希表的基础


    }
    public static void main1(String[] args) {
        String str = "hello";//区别于C语言 java当中字符串 没有以\0结尾这样的说法！
        System.out.println(str);
        System.out.println(str.length());

        System.out.println("===============");
        String str1 = "";
        System.out.println(str1.isEmpty());//判断字符串是不是空的

        String str2 = null;//str2这个引用 不指向任何的对象
        //System.out.println(str2.isEmpty());
        System.out.println("hello".length());


        System.out.println("===============");



/*


        int[] array2 = {1,2,3,4,5};
        System.out.println(array2.length);


        String str2 = new String("world");
        System.out.println(str2);

        char[] array = {'a','b','c'};//字符数组
        String str3 = new String(array);
        System.out.println(str3);*/


    }
}
